package com.ssm.design.chain.handler;

import com.ssm.design.chain.OrderHandlerChain;
import com.ssm.design.chain.context.OrderHandleContext;
import com.ssm.design.common.dto.OrderDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import static com.ssm.design.common.constant.OrderConstant.ORDER_HANDLER_WEIGHT_VIP;

@Order(ORDER_HANDLER_WEIGHT_VIP)
@Component
public class VipOrderHandler extends AbstractHandler {

    @Autowired
    private ApplicationContext applicationContext;

    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    @Override
    public void doHandle(OrderHandleContext context, OrderHandlerChain chain) {



        OrderDto orderDto = context.getOrderDto();
        if (orderDto.getVipLevel() > 2) {
            orderDto.setAmount(orderDto.getAmount() - 5);
        }
        // 调用下一个处理器进行处理
        chain.handle(context);
    }

}